<?php

/*
 * Author: Quan Van Sinh
 * Email : qvsinh@gmail.com
 * Mobile: 0972405165
 */

class share {

    function share() {
        
    }

    function listMyAlbum($limit=10) {
        global $db;
        $mid = intval($_GET['mid']);

        if ($mid) {
            $page = intval($_GET['page']);

            if ($page < 1) {
                $page = 1;
            }

            $sql = "SELECT count(*) as numrows FROM album WHERE mid=$mid";
            $arrTotalRows = $db->query_first($sql);
            $totalPages = ceil($arrTotalRows['numrows'] / $limit);
            $start = (($page * $limit) - $limit);

            $sql = "SELECT a.*,(SELECT image FROM images WHERE aid=a.id AND mid=$mid and active=1 LIMIT 1) as thumb,(select count(*) FROM images WHERE aid=a.id AND mid=$mid and active=1) as count_num  FROM album a WHERE a.mid=$mid order by count_num desc LIMIT $start,$limit";
            $rs = $db->query($sql);
            return array('rs' => $rs, 'page' => $page, 'totalPage' => $totalPages);
        } else {
            return false;
        }
    }

    function listMyImage($mid, $aid) {
        global $db;
        if ($mid && $aid) {
            $page = intval($_GET['page']);
            $sql = "SELECT * FROM images WHERE mid=$mid AND aid=$aid and active=1";
            $rs = $db->query($sql);
            while ($row = $db->fetch_array($rs)) {
                $arrImages[$row['id']] = $row;
            }
            return $arrImages;
        } else {
            return false;
        }
    }

}

?>
